﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.Utilities;
using CuaHangMayTinh.DataProvider;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.DataAccessLayer;
using System.Data;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    /// <summary>
    /// Lớp GroupUserManager
    /// </summary>
    public class GroupUserManager
    {
        /// <summary>
        /// Khởi tạo đối tượng GroupUserDA
        /// </summary>
        private static GroupUserDA adapter = null;

        static GroupUserManager()
        {
            if (adapter == null)
                adapter = new GroupUserDA();
        }

        /// <summary>
        /// Hàm thêm 1 SubGroupUserEntity mới
        /// </summary>
        /// <param name="entity">GroupUserEntity muốn thêm mới</param>
        /// <returns></returns>
        public static int Insert(GroupUserEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm Cập nhật 1 SubGroupUserEntity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate(GroupUserEntity entity)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm tìm tất cả thông tin  Quyền
        /// </summary>
        /// <returns></returns>
        public static DataTable Find_All()
        {
            try
            {
                return adapter.Find_All();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm chuyển từ 1 Datatbale chứ thông tin của GroupUser thành 1 List GroupUserEntity
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<GroupUserEntity> ConvertToList(DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }
    }
}




